﻿'Params
'tag (Required) : The tag name
'limit (Optional) : The number of results to fetch per page. Defaults to 50.
'page (Optional) : The page number to fetch. Defaults to first page.
'api_key (Required) : A Last.fm API key.
'Auth
'This service does not require authentication. 

Public Structure TagGetTopAlbumsResponse
    Public albums() As Album
End Structure

Public Class TagGetTopAlbums
    Inherits BaseRequest

    Dim tag As String = ""
    Dim page As String = ""
    Dim limit As String = ""

    Public xmlresponse As XDocument = Nothing

    Public Sub New(tag As String, page As String, limit As String)
        Me.tag = tag
        Me.page = page
        Me.limit = limit
    End Sub

    Public Sub sendRequest()
        InitializeMembers("tag.getTopAlbums")

        AddMember("tag", tag, True)
        AddMember("page", page, False)
        AddMember("limit", limit, False)

        xmlresponse = sendPOSTResponse()
    End Sub

    Public Function getResponse() As TagGetTopAlbumsResponse
        Dim response As New TagGetTopAlbumsResponse
        Dim count As Integer
        Try
            count = xmlresponse.<lfm>.<topalbums>.Count()
        Catch ex As Exception
        End Try
        If (count > 0) Then
            ReDim response.albums(count - 1)
        End If
        For i As Integer = 0 To count - 1
            response.albums(i) = New Album(xmlresponse.<lfm>.<topalbums>(i))
        Next

        Return response
    End Function
End Class
